/**
 * 
 */
package com.glela.common.exception;

import com.glela.common.exception.BusinessError;

/**
 * @author liujie
 *
 * 业务异常编码详细定义
 */
public enum BusinessError {
	/**
	 * system error code
	 */
	C10000("10000","succuss"),
	C9999("9999","system error"),
	C8888("8888","biz error"),
	C0000("0000","invalid arguments"),
	C0001("0001","object not found"),
	C20001("20001","goods stock  is insufficient"),//商品不足
	C20002("20002","point is insufficient"),//积分不足 
 	C20003("20003","flag is null"),//分享标记为空
 	C20004("20004","shared mobile is null"),//被分享手机号为空
 	C20005("20005","flag matching error"),//分享标记为空
 	C20006("20006","can't shared by self"),//不能分享给自己
 	C20007("20007","Signin activity is closed"),//签到活动关闭
 	
 	C80000("80000","query goods category error"),//查询商品分类错误
 	C80001("80001","query goods by categoryId error"),//根据分类Id查询商品错误
 	C80003("80003","goods didn't exist"),
 	C80004("80003","query goods error"),
	
	/**
	 * 非法参数异常（详细错误）
	 */
	C0000_0001("00000001","用户名不能为空"),
	C0000_0002("00000002","用户名格式错误"),
	C0000_0003("00000003","用户昵称包含敏感词");

	
	/**
	 * error code
	 */
	private final String code;
	/**
	 * error text
	 */
	private final String text;
	/**
	 * get error code
	 * @return
	 */
	public String getCode(){
    	return this.code;
    }
	/**
	 * get error text
	 * @return
	 */
    public String getText() {
		return this.text;
	}
	
    /**
     * DSError constructor
     * @param code
     * @param text
     */
	private BusinessError(String code,String text) {
        this.code = code;
        this.text = text;
    }
	
	public static BusinessError valueByCode(String code) {
		for(BusinessError error : BusinessError.values()) {
			if(error.code.equals(code)) {
				return error;
			}
		}
		return null;
	}
	
}
